package com.example.surfaceviewcamera;


import android.hardware.Camera;
import android.os.Bundle;
import android.widget.FrameLayout;
import android.app.Activity;

public class MainActivity extends Activity {

	private Camera mCamera;
	private CameraSurfaceView mPreview;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		
		mPreview = new CameraSurfaceView(this);
		mPreview.setCamera(mCamera);
		
		FrameLayout preview = (FrameLayout)findViewById(R.id.camera_preview);
		preview.addView(mPreview);
	}

	@Override
	protected void onPause() {
		super.onPause();
		
		if(mCamera != null){
			mPreview.setCamera(null);
			mCamera.release();
			mCamera = null;
		}
	}

	@Override
	protected void onResume() {
		super.onResume();
		
		mCamera = Camera.open();
		mPreview.setCamera(mCamera);
	}
}
